package han.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @fileName: PropUtil
 * @author: Han
 * @date: 2018/6/26 10:15
 * @dscription: TODO
 */
public class PropUtil {
    /**
     * 加载属性文件
     * @param fileName 文件地址
     * @return 配置对象
     */
    public static Properties loadProps(String fileName) {
        Properties properties = null;
        InputStream inputStream = null;
        try {
            inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
            if (inputStream == null) {
                throw new FileNotFoundException(fileName + " file is not found!");
            }
            properties = new Properties();
            properties.load(inputStream);
        } catch (IOException e) {
            //LOGGER.error("load properties file failure", e);
            System.out.println("load properties file failure:" + e);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    //LOGGER.error("close input stream failure", e);
                    System.out.println("close input stream failure:" + e);
                }
            }
        }
        return properties;
    }
}
